route.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { ApiPath } from "@/app/constant";
  2. import { NextRequest } from "next/server";
  3. import { handle as openaiHandler } from "../../openai";
  4. import { handle as azureHandler } from "../../azure";
  5. import { handle as googleHandler } from "../../google";
  6. import { handle as anthropicHandler } from "../../anthropic";
  7. import { handle as baiduHandler } from "../../baidu";
  8. import { handle as bytedanceHandler } from "../../bytedance";
  9. import { handle as alibabaHandler } from "../../alibaba";
  10. import { handle as moonshotHandler } from "../../moonshot";
  11. import { handle as stabilityHandler } from "../../stability";
  12. import { handle as iflytekHandler } from "../../iflytek";
  13. import { handle as deepseekHandler } from "../../deepseek";
  14. import { handle as siliconflowHandler } from "../../siliconflow";
  15. import { handle as xaiHandler } from "../../xai";
  16. import { handle as chatglmHandler } from "../../glm";
  17. import { handle as proxyHandler } from "../../proxy";
  18. import { handle as ai302Handler } from "../../302ai";
  19. async function handle(
  20. req: NextRequest,
  21. { params }: { params: { provider: string; path: string[] } },
  22. ) {
  23. const apiPath = `/api/${params.provider}`;
  24. console.log(`[${params.provider} Route] params `, params);
  25. switch (apiPath) {
  26. case ApiPath.Azure:
  27. return azureHandler(req, { params });
  28. case ApiPath.Google:
  29. return googleHandler(req, { params });
  30. case ApiPath.Anthropic:
  31. return anthropicHandler(req, { params });
  32. case ApiPath.Baidu:
  33. return baiduHandler(req, { params });
  34. case ApiPath.ByteDance:
  35. return bytedanceHandler(req, { params });
  36. case ApiPath.Alibaba:
  37. return alibabaHandler(req, { params });
  38. // case ApiPath.Tencent: using "/api/tencent"
  39. case ApiPath.Moonshot:
  40. return moonshotHandler(req, { params });
  41. case ApiPath.Stability:
  42. return stabilityHandler(req, { params });
  43. case ApiPath.Iflytek:
  44. return iflytekHandler(req, { params });
  45. case ApiPath.DeepSeek:
  46. return deepseekHandler(req, { params });
  47. case ApiPath.XAI:
  48. return xaiHandler(req, { params });
  49. case ApiPath.ChatGLM:
  50. return chatglmHandler(req, { params });
  51. case ApiPath.SiliconFlow:
  52. return siliconflowHandler(req, { params });
  53. case ApiPath.OpenAI:
  54. return openaiHandler(req, { params });
  55. case ApiPath["302.AI"]:
  56. return ai302Handler(req, { params });
  57. default:
  58. return proxyHandler(req, { params });
  59. }
  60. }
  61. export const GET = handle;
  62. export const POST = handle;
  63. export const runtime = "edge";
  64. export const preferredRegion = [
  65. "arn1",
  66. "bom1",
  67. "cdg1",
  68. "cle1",
  69. "cpt1",
  70. "dub1",
  71. "fra1",
  72. "gru1",
  73. "hnd1",
  74. "iad1",
  75. "icn1",
  76. "kix1",
  77. "lhr1",
  78. "pdx1",
  79. "sfo1",
  80. "sin1",
  81. "syd1",
  82. ];